import Request from "@/sdk/pocky-request/index.js"; //引入
import CFG from "@/common/config.js";
/**
 * order store 订单
 */
const order = {
	// 状态
	state: {

	},
	// 内部派生
	getters: {

	},
	// 同步方法 commit
	mutations: {

	},
	// 异步方法 dispatch
	actions: {
		/**
		 * @description 获取订单列表
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetOrderList(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/order/list.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '订单列表获取失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '订单列表获取失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		apiGetOrderDt(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/order/detail.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)

					} else {
						uni.showToast({
							title: '订单获取失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '订单获取失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @param {Object} context
		 * @param {Object} _data 获取常规活动订单
		 */
		apiGetOrderDtcg(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/usual/detail.do',
					method: 'GET',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
		
					} else {
						uni.showToast({
							title: '订单获取失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '订单获取失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @description 获取订单签名
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetOrderSign(context, _data) {
			return new Promise((resolve, reject) => {
				let url = '';
				if (_data.payType == 'wxpay') { //微信支付
					url = '/pay/wx/getSign.do'
				} else { //支付宝支付
					url = '/pay/ali/getSign.do'
				}
				delete _data.payType;
				Request().request({
					url: url,
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '签名获取失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '签名获取失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetMpSign(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/pay/wx/getMpSign.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '签名获取失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '签名获取失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @param {Object} context
		 * @param {Object} _data 常规活动获取订单签名的接口
		 */
		apiGetMpSignNew(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/pay/wx/getMpSignNew.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '签名获取失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '签名获取失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @description 获取支付服务供应商
		 * @param {Object} context
		 * @param {Object} _data
		 */
		uniGetPayProvider(context) {
			return new Promise((resolve, reject) => {
				uni.getProvider({
					service: 'payment',
					success: function(res) {
						resolve(res);
					},
					fail: (err) => {
						uni.showToast({
							title: '获取支付供应商失败',
							icon: 'none'
						});
						reject(err);
					}
				});
			})
		},
		/**
		 * @description 获取体验码
		 * @param {Object} context
		 * @param {Object} _id
		 */
		apiGetEpCode(context, _id) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/order/get_code.do',
					method: 'post',
					data: {
						order_id: _id
					}
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '体验码获取失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '体验码获取失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})

		},
		/**
		 * @description 获取退款金额
		 * @param {Object} context
		 * @param {Object} _id
		 */
		apiGetRefoundPrice(context, _id) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/order/handle/toRefund.do',
					method: 'post',
					data: {
						order_id: _id
					}
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '获取退款金额失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '获取退款金额失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @description 处理退款
		 * @param {Object} context
		 * @param {Object} _data+
		 */
		apiApplyRefound(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/order/handle/add.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '提交退款申请失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '提交退款申请失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		
		/**
		 * @description 常规活动处理退款
		 * @param {Object} context
		 * @param {Object} _data+
		 */
		apirefundUsual(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/usual/refundUsual.do',
					method: 'GET',
					data: _data
				}).then(res => {
					console.log(res)
					if (res.data.code == 4) {
						resolve(res)
					} else {
						uni.showToast({
							title: '提交退款申请失败,' + res.data.date,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '提交退款申请失败,' + res.data.date,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @description 获取退款详情
		 * @param {Object} context
		 * @param {Object} _oid
		 */
		apiGetRefoundDt(context, _oid) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/order/refund/detail.do',
					method: 'post',
					data: {
						refundId: _oid
					}
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '获取退款详情失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '获取退款详情失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @description 获取协商历史
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetAfterList(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/order/handle/list.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '获取退款详情失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '获取退款详情失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * 评价订单
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiPostEvaluate(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/order/comment/add.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '评价失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '评价失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @description 获取我的评论
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetMyEvaluate(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/order/comment/listSelf.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '获取评论失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '获取评论失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @description 通过课程ID获取最新评价
		 * @param {Object} context
		 * @param {Object} _data
		 * 	"courseId":1,
	"page_size":10
		 */
		apiGetNewElt(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/course/comment/latest.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '获取评论失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '获取评论失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @description 通过课程ID获取全部评价
		 * @param {Object} context
		 * @param {Object} _data
		 * 	"courseId":1,
	"page_no":1,
	"page_size":10
		 */
		apiGetAllElt(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/course/comment/list.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '获取评论失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '获取评论失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @description 通过ID获取优惠券详情
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetCouponById(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/coupon/detail.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						uni.showToast({
							title: '优惠券详情获取失败,' + res.data.msg,
							icon: 'none'
						});
						reject(res)
					}
				}).catch(err => {
					uni.showToast({
						title: '优惠券详情获取失败,' + res.data.msg,
						icon: 'none'
					});
					reject(res)
				})
			})
		},
		/**
		 * @description 领取优惠券
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiReceiveCoupon(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/coupon/fetch.do',
					method: 'post',
					data: _data
				}).then(res => {
					resolve(res)
				}).catch(err => {

					reject(res)
				})
			})
		},
		/**
		 * @description 获取可用优惠券列表
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetCanUserCoupon(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: '/coupon/list.do',
					method: 'post',
					data: _data
				}).then(res => {
					if (res.data.code == 1) {
						resolve(res)
					} else {
						// uni.showToast({
						// 	title: '领取成功,'+res.data.msg,
						// 	icon: 'none'
						// });
						reject(res)
					}
				}).catch(err => {
					// uni.showToast({
					// 	title: '领取失败,'+res.data.msg,
					// 	icon: 'none'
					// });
					reject(res)
				})
			})
		},
		/**
		 * 获取选课情况
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetSelectClass(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: CFG.apiUrl + 'training-server/activity/getCourseData.do',
					method: 'post',
					data: {
						orderNo: _data.goodid
					}
				}).then(res => {					
					Request().request({
						url: CFG.apiUrl + 'training-server/activity/getlessons.do',
						method: 'post',
						data: {
							uid: _data.uid,
							actId: res.data.actId //活动详情的id
						}
					}).then(rsn => {
						
						resolve(rsn)
					}).catch(err => {
						reject(rsn)
					})
				}).catch(err => {

					reject(err)
				})
			})
		},
		/**
		 * @param {Object} context 获取已经选择课程
		 * @param {Object} _data
		 */
		apiReportSelectClassyx(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: CFG.apiUrl + 'training-server/activity/getCourseData.do',
					method: 'post',
					data: {
						orderNo: _data.goodid
					}
				}).then(res => {
					
					resolve(res)
				}).catch(err => {
					reject(res)
				})
			})
		},


		/**
		 * @description 提交选课
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiReportSelectClass(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: CFG.apiUrl + 'training-server/activity/setCourseData.do',
					method: 'post',
					data: _data
				}).then(res => {
					resolve(res)
				}).catch(err => {
					reject(res)
				})
			})
		},
		/** 核销历史的接口
		 * @param {Object} context
		 * @param {Object} _data
		 */
		apiGetHexiaoList(context, _data) {
			return new Promise((resolve, reject) => {
				Request().request({
					url: CFG.apiUrl + 'training-server/activity/tryCodelist.do',
					// url:CFG.apiUrl+'activity/tryCodelist.do',
					method: 'POST',
					data: _data
				}).then(res => {
					resolve(res)
				}).catch(err => {

					reject(err)
				})
			})
		},

	}
}

export default order
